package com.pickerview.lib;

import java.util.List;

/**
 * The simple Array wheel adapter
 * 
 * @param <T>
 *          the element type
 */
public class ArrayWheelAdapter<T> implements WheelAdapter {

  /** The default items length */
  public static final int DEFAULT_LENGTH = 6;

  // items
  private List<T> items;
  // length
  private int length;

  /**
   * Constructor
   * 
   * @param items
   *          the items
   * @param length
   *          the max items length
   */
  public ArrayWheelAdapter(List<T> items, int length) {
    this.items = items;
    this.length = length;
  }

  /**
   * Contructor
   * 
   * @param items
   *          the items
   */
  public ArrayWheelAdapter(List<T> items) {
    this(items, DEFAULT_LENGTH);
  }

  @Override
  public String getItem(int index) {
    if (index >= 0 && index < items.size()) {
      return items.get(index).toString();
    }
    return null;
  }

  @Override
  public int getItemsCount() {
    return items.size();
  }

  @Override
  public int getMaximumLength() {
//    int maxLength = 0;
//    List<Integer> maxLs = new ArrayList<Integer>();
//    if (!items.isEmpty()) {
//      for (int i = 0; i < items.size(); i++) {
//        maxLs.add(items.get(i).toString().length());
//      }
//      maxLength = Collections.max(maxLs)+3;
//      Log.d("ArrayWheelAdapter", "最大长度="+maxLength);
//      return maxLength;
//    }else{
//      return length;
//    }
    return length;
  }

}
